/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package au.edu.swin.bank.persistence.entity;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author Luke Horvat
 */
@Entity
@Table(name = "ACCOUNT")
@NamedQueries({
    @NamedQuery(name = "Account.findAll", query = "SELECT a FROM Account a"),
    @NamedQuery(name = "Account.findByAccountid", query = "SELECT a FROM Account a WHERE a.accountid = :accountid"),
    @NamedQuery(name = "Account.findByBalance", query = "SELECT a FROM Account a WHERE a.balance = :balance"),
    @NamedQuery(name = "Account.findByRemoved", query = "SELECT a FROM Account a WHERE a.removed = :removed")})
public class Account implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ACCOUNTID")
    private BigInteger accountid;
    @Column(name = "BALANCE")
    private Double balance;
    @OneToMany(mappedBy = "account")
    private Collection<Archive> archiveCollection;
    @JoinColumn(name = "CUSTID", referencedColumnName = "CUSTID")
    @ManyToOne
    private Customer customer;
    @Basic(optional = false)
    @Column(name = "REMOVED")
    private int removed;

    public Account() {
    }

    public Account(BigInteger accountid) {
        this.accountid = accountid;
    }

    public Account(BigInteger accountid, int removed) {
        this.accountid = accountid;
        this.removed = removed;
    }

    public BigInteger getAccountId() {
        return accountid;
    }

    public void setAccountId(BigInteger accountid) {
        this.accountid = accountid;
    }

    public Double getBalance() {
        return balance;
    }

    public void setBalance(Double balance) {
        this.balance = balance;
    }

    public Collection<Archive> getArchiveCollection() {
        return archiveCollection;
    }

    public void setArchiveCollection(Collection<Archive> archiveCollection) {
        this.archiveCollection = archiveCollection;
    }

    public Customer getCustomer() {
        return customer;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    public int getRemoved() {
        return removed;
    }

    public void setRemoved(boolean aRemoved) {
        if (aRemoved)
            this.removed = 1;
        else
            this.removed = 0;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (accountid != null ? accountid.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Account)) {
            return false;
        }
        Account other = (Account) object;
        if ((this.accountid == null && other.accountid != null) || (this.accountid != null && !this.accountid.equals(other.accountid))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "au.edu.swin.bank.persistence.entity.Account[accountid=" + accountid + "]";
    }

}
